<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <meta name="author" content="Openshift Assisted Service Team">
  
  <link rel="shortcut icon" href="../../img/favicon.ico">
  <title>Migrations - Openshift Assisted Service</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700" />

  <link rel="stylesheet" href="../../css/theme.css" />
  <link rel="stylesheet" href="../../css/theme_extra.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" />
  
  <script>
    // Current page data
    var mkdocs_page_name = "Migrations";
    var mkdocs_page_input_path = "dev/migrations.md";
    var mkdocs_page_url = null;
  </script>
  
  <script src="../../js/jquery-2.1.1.min.js" defer></script>
  <script src="../../js/modernizr-2.8.3.min.js" defer></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script> 
  
</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
    <div class="wy-side-scroll">
      <div class="wy-side-nav-search">
        <a href="../.." class="icon icon-home"> Openshift Assisted Service</a>
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" title="Type search term here" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../..">OAS Home</a>
                    </li>
                </ul>
                <p class="caption"><span class="caption-text">OAS Deployment</span></p>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../../user-guide/assisted-service-on-local/">OAS Running on Local</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../../user-guide/assisted-service-on-openshift/">OAS Running on Openshift</a>
                    </li>
                </ul>
                <p class="caption"><span class="caption-text">Openshift Deployment</span></p>
                <ul>
                    <li class="toctree-l1"><a class="reference internal" href="../../user-guide/user-guide/">User Guide Index</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../../user-guide/deploy-on-local/">OCP Deployment on Local</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../../user-guide/deploy-on-bare-metal/">OCP Deployment on Bare Metal</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../../user-guide/deploy-on-vsphere/">OCP Deployment on vSphere</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../../user-guide/deploy-on-RHEV/">OCP Deployment on RHEV</a>
                    </li>
                    <li class="toctree-l1"><a class="reference internal" href="../../user-guide/deploy-on-OSP/">OCP Deployment on Openstack</a>
                    </li>
                </ul>
                <p class="caption"><span class="caption-text">OAS Development</span></p>
                <ul class="current">
                    <li class="toctree-l1 current"><a class="reference internal current" href="./">Migrations</a>
    <ul class="current">
    <li class="toctree-l2"><a class="reference internal" href="#why">Why?</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#how">How?</a>
    </li>
    <li class="toctree-l2"><a class="reference internal" href="#adding-a-new-migration">Adding a new migration</a>
    </li>
    </ul>
                    </li>
                </ul>
      </div>
    </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../..">Openshift Assisted Service</a>
      </nav>

      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../..">Docs</a> &raquo;</li>
    
      
        
          <li>OAS Development &raquo;</li>
        
      
    
    <li>Migrations</li>
    <li class="wy-breadcrumbs-aside">
      
    </li>
  </ul>
  
  <hr/>
</div>
          <div role="main">
            <div class="section">
              
                <h2 id="migrations">Migrations</h2>
<h3 id="why">Why?</h3>
<p>There are some database changes that GORM auto migration <a href="https://v1.gorm.io/docs/migration.html#Auto-Migration">will not handle for us</a>.
These need to be dealt with separately.</p>
<h3 id="how">How?</h3>
<p>To do this we are using a migration module called <a href="https://pkg.go.dev/gopkg.in/gormigrate.v1">gormigrate</a>.
Migrations are run at startup right after the automigration is run.</p>
<h3 id="adding-a-new-migration">Adding a new migration</h3>
<ul>
<li>Each migration should have a separate file in <code>/internal/migrations</code> prefixed with a timestamp which will also be the migration ID</li>
<li>Each migration should have a single function named to describe the change which returns a <code>*gormigrate.Migration</code><ul>
<li>Both migrate (up) and rollback (down) should be implemented if possible</li>
</ul>
</li>
<li>Every migration should have a corresponding test (especially for migrations which are changing data)</li>
<li>A new migration scaffold can be created using <code>MIGRATION_NAME=someMigrationNameHere make generate-migration</code><ul>
<li>This will give the migration files a proper timestamp as well as (empty) tests</li>
</ul>
</li>
</ul>
<p>To be run, every migration function should be added to the list in <code>migrations.all()</code></p>
              
            </div>
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
      
        <a href="../../user-guide/deploy-on-OSP/" class="btn btn-neutral" title="OCP Deployment on Openstack"><span class="icon icon-circle-arrow-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <!-- Copyright etc -->
    
  </div>

  Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
      
        </div>
      </div>

    </section>

  </div>

  <div class="rst-versions" role="note" aria-label="versions">
    <span class="rst-current-version" data-toggle="rst-current-version">
      
          <a href="https://github.com/openshift/assisted-service" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
      
      
        <span><a href="../../user-guide/deploy-on-OSP/" style="color: #fcfcfc;">&laquo; Previous</a></span>
      
      
    </span>
</div>
    <script>var base_url = '../..';</script>
    <script src="../../js/theme.js" defer></script>
      <script src="../../search/main.js" defer></script>
    <script defer>
        window.onload = function () {
            SphinxRtdTheme.Navigation.enable(true);
        };
    </script>

</body>
</html>
